#!/bin/bash

source src/conf/config.conf
net_url1=http://ftp.netbsd.org/pub/NetBSD/NetBSD-$netbsd_ver/$netbsd_arch/installation/misc/
net_url2=http://ftp.netbsd.org/pub/NetBSD/NetBSD-$netbsd_ver/$netbsd_arch/binary/kernel/

echo " Downloading NetBSD ..."

cd $tftp_dir

    for ARCH in i386 amd64; do
        mkdir -p "net/${ARCH}"

wget -q -c $net_url1/pxeboot_ia32.bin -O netbsd.bin && mv netbsd.bin net/$netbsd_arch/
wget -q -c $net_url2/netbsd-INSTALL.gz && gunzip netbsd-INSTALL.gz && mv netbsd-INSTALL net/$netbsd_arch/

#wget -c http://ftp.netbsd.org/pub/NetBSD/NetBSD-$netbsd_ver/$netbsd_arch/installation/misc/pxeboot_ia32.bin -O netbsd.bin && mv netbsd.bin net/$netbsd_arch/
#wget -c http://ftp.netbsd.org/pub/NetBSD/NetBSD-$netbsd_ver/$netbsd_arch/binary/kernel/netbsd-INSTALL.gz && gunzip netbsd-INSTALL.gz && mv netbsd-INSTALL net/$netbsd_arch/

 done
 
yes | cp -Rv net/* BSD/netbsd/

sleep 3
mv net/ tars/


## MENU

cat >> pxelinux.cfg/bsd << EOF
  

DEFAULT install
PROMPT 1
TIMEOUT 50 
menu title BSD Installer
menu include pxelinux.cfg/graphics.conf
MENU BACKGROUND pxelinux.cfg/background.png


MENU BEGIN oses-submenu
 LABEL Previous
        MENU LABEL Previous Menu
        TEXT HELP
        Return to previous menu
        ENDTEXT
        MENU EXIT
 MENU TITLE Install NET BSD
MENU INCLUDE pxelinux.cfg/netbsd.cfg
MENU END


EOF

touch pxelinux/netbsd.cfg

for ARCH in i386 amd64; do
echo "menu include pxelinux.cfg/graphics.conf"
echo "MENU BACKGROUND pxelinux.cfg/background.png"
        echo "label Install NET BSD  ${ARCH}"
        echo "      menu label NET BSD  ${ARCH}"
        echo "      kernel BSD/netbsd/${ARCH}/netbsd.bin"
        echo "      append BSD/netbsd/${ARCH}/netbsd-INSTALL"
        echo "	   boot tftp:/BSD/netbsd/${ARCH}/netbsd-INSTALL"
   
echo " "
	echo " TEXT HELP"
       echo "  Install NET BSD ${ARCH}"
        echo " ENDTEXT"


done >> pxelinux.cfg/netbsd.cfg


    
